#!/bin/bash

if [ "$1" = "make" ]; then
  # make build dir if it doesnt exist:
  if [ ! -d "build" ]; then
    mkdir build
  fi
  # move to build dir:
  cd build
  # generate make file:
  cmake ..
  #test if cmake worked: test most recent return value $?
  if [ $? -ne 0 ]; then
    echo "CMAKE FAILED"
    exit 1
  fi
  #cmake worked so make it:
  echo "building..."
  make
  exit $?
fi

if [ "$1" = "clean" ]; then
  rm -rf build
  mkdir build
  exit $?
fi

if [ "$1" = "run" ]; then
  build/main
  exit $?
fi

echo "compile [clean|make|run]"
